package com.example.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.feignclient.OrderFeignClient;
import com.example.feignclient.PointsFeignClient;
import com.example.feignclient.StorageFeignClient;

import io.seata.spring.annotation.GlobalTransactional;

@Service
public class MallService {
	@Resource
	OrderFeignClient orderFeignClient;
	@Resource
	PointsFeignClient pointsFeignClient;
	@Resource
	StorageFeignClient storageFeignClient;

	@GlobalTransactional(name = "seata-group-tx-mall", rollbackFor = { Exception.class })
	public String sale(Integer orderId, Integer memberId, Integer goodsId, Integer points, Integer quantity) {
		String orderResult = orderFeignClient.createOrder(orderId, memberId, goodsId, points, quantity);
		String pointsResult = pointsFeignClient.addPoints(memberId, points);
		String storageResult = storageFeignClient.reduceStorage(goodsId, quantity);
		return orderResult + " / " + pointsResult + " / " + storageResult;
	}
}